/*
 * FramePreguntaAfectivoConsejos.java
 *
 * Created on 29 de mayo de 2009, 20:27
 */


/**
 *
 * @author  David
 */

package GUI;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import jess.*;

/**
 *
 * @author Tony
 */
public class FramePreguntaAfectivoConsejos extends javax.swing.JFrame {

    private JFrame framePadre;
    private Vector vector;
    BufferedWriter writer;
    BufferedReader reader;
    Rete engine;
    Batch batch;
    /** Creates new form Consejos */
    public FramePreguntaAfectivoConsejos(JFrame fr) throws JessException {
    	engine = new Rete ();
    	batch = new Batch();
        this.setVisible(true);
        this.framePadre=fr;
        initComponents();

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jComboBox_Experiencia = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jComboBox_Motivacion = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jComboBox_Edad = new javax.swing.JComboBox();
        jButtonVolver = new javax.swing.JButton();
        jButtonAsesorar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jLabel1.setText("Consejos Generales");

        jLabel2.setText("Experiencia");

        jComboBox_Experiencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Estudiando", "Poca", "Mucha" }));

        jLabel3.setText("Motivación");

        jComboBox_Motivacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Dinero", "Realización" }));

        jLabel4.setText("Edad");

        jComboBox_Edad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<27", "27-45", ">45" }));

        jButtonVolver.setText("Volver");
        jButtonVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVolverActionPerformed(evt);
            }
        });

        jButtonAsesorar.setText("Asesorar");
        jButtonAsesorar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonAsesorarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(150, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(141, 141, 141))
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jComboBox_Edad, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBox_Motivacion, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBox_Experiencia, 0, 148, Short.MAX_VALUE))
                .addContainerGap(126, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(78, 78, 78)
                .addComponent(jButtonVolver)
                .addGap(84, 84, 84)
                .addComponent(jButtonAsesorar)
                .addContainerGap(100, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(jLabel1)
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBox_Experiencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBox_Motivacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBox_Edad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonVolver)
                    .addComponent(jButtonAsesorar))
                .addGap(24, 24, 24))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVolverActionPerformed
    this.setVisible(false);     
    this.framePadre.setVisible(true);
}//GEN-LAST:event_jButtonVolverActionPerformed

private void jButtonAsesorarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonAsesorarMouseClicked
    {
            try {
                int uno = jComboBox_Edad.getSelectedIndex();
                int dos = jComboBox_Motivacion.getSelectedIndex();
                int tres = jComboBox_Experiencia.getSelectedIndex();
                if (tres == 0) {
                    engine.assertString("(anios <27)");
                }
                if (tres == 1) {
                    engine.assertString("(anios 27-45)");
                }
                if (tres == 2) {
                    engine.assertString("(anios >45)");
                }
                if (dos == 0) {
                    engine.assertString("(motivacion dinero)");
                }
                if (dos == 1) {
                    engine.assertString("(motivacion realizacion)");
                }
                if (uno == 0) {
                    engine.assertString("(experiencia estudiando)");
                }
                if (uno == 1) {
                    engine.assertString("(experiencia poca)");
                }
                if (uno == 2) {
                    engine.assertString("(experiencia mucha)");
                }
                //Batch.batch("./GUI/consejos.clp", engine);
                batch.batch("./GUI/consejos.clp",engine);
                //engine.reset();
                BufferedReader reader2= new BufferedReader(new InputStreamReader(new
                FileInputStream("C://salida.txt")));
                vector=new Vector();
                String linea;
                try {
                    linea = reader2.readLine();

                    System.out.println(linea);
                    JFrame  u= new Salida_Consejos(this.framePadre,linea);
                    this.setVisible(false);
                } catch (IOException ex) {
                    Logger.getLogger(FramePreguntaAfectivoConsejos.class.getName()).log(Level.SEVERE, null, ex);
                }

            } catch (FileNotFoundException ex) {
                Logger.getLogger(FramePreguntaAfectivoConsejos.class.getName()).log(Level.SEVERE, null, ex);
            } catch (JessException ex) {
                Logger.getLogger(FramePreguntaAfectivoConsejos.class.getName()).log(Level.SEVERE, null, ex);
            }
        }




}//GEN-LAST:event_jButtonAsesorarMouseClicked

   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAsesorar;
    private javax.swing.JButton jButtonVolver;
    private javax.swing.JComboBox jComboBox_Edad;
    private javax.swing.JComboBox jComboBox_Experiencia;
    private javax.swing.JComboBox jComboBox_Motivacion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables

}
